import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.ListIterator.*;
import java.util.Iterator;
import java.util.*;


package com.student

class Student1 implements Comparator<Student1>, Comparable<Student1>{
	private int rollno;
	private String name;
	private int age;
	Student1(){
		
	}
	
	public String getName(){
		
		return name;
	}
	
	public String setName(String name){
		return this.name;
		
	}

public int getRollno(){
		
		return rollno;
	}
	
	public int setRollno(int rollno){
		return this.rollno;
		
	}
public int getAge(){
		
		return age;
	}
	
	public int setAge(String age){
		return this.age;
		
	}
	public Student1(int rollno, String name, int age){
		 this.rollno=rollno;
		 this.name=name;
		 this.age=age;
	 }
	 public String toString(){
		 
		 return this.name;
		 
	 }
	 
	 public int compareTo(Student1 s){
		 return name.compareTo(s.getName());
		 
	 }
	 public int compare(Student1 d, Student1 d1){
	      return d.rollno - d1.rollno;
	   }
	
	
}
public class SortByRollno{
	public static void main (String[]args){
	
	List<Student1> list= new ArrayList<Student1>();
	 Student1 s1=new Student1(10,"Ravi",23);
	 Student1 s2=new Student1(12,"Mahesh",18);
	 Student1 s3=new Student1(11,"Kumar",25);
	list.add(s1);
	list.add(s2);
	list.add(s3);
	Collections.sort(list);
	for(Student1 ss:list){
		
		System.out.println(ss.getName());
	}

	ListIterator itr=list.listIterator();

	while(itr.hasPrevious()){
		
		Student1 st=(Student1)itr.previous();
		System.out.println(st.getRollno()+"  "+st.getName()+ " "+st.getAge());
	}
	
	
	System.out.println();
	
	Collections.sort(list,new Student1());
	System.out.println("Sorted based on Rollno");
      for(Student1 ss:list){
		
		System.out.println(ss.getRollno()+" "+ss.getName()+"  "+ss.getAge());
	}
	
}

}


